package leecode.LinkedList.DoublePoint;


/**
 * 判断链表中是否存在环，具体见141题，描述不清
 */
public class HasCycle {

    public static void main(String[] args) {

    }


  //    Definition for singly-linked list.
      class ListNode {
          int val;
          ListNode next;
          ListNode(int x) {
              val = x;
              next = null;
          }
      }


        public boolean hasCycle(ListNode head) {
            if(head==null || head.next==null){
                return false;
            }

            ListNode fast = head.next;
            ListNode slow = head;

            while(fast!=null &&fast.next!=null){
                fast = fast.next.next;
                slow = slow.next;
                if(slow==fast){
                    return true;
                }
            }
            return false;
        }
}
